package com.gxa.admin.controller;

import com.gxa.admin.pojo.dto.BannerDto;
import com.gxa.admin.pojo.vo.BannerVo;
import com.gxa.admin.service.BannerService;
import com.gxa.core.result.Result;
import com.gxa.core.result.ResultUtils;
import com.gxa.pojo.Banner;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "轮播图接口")
@RestController
@RequestMapping("/banner")
public class BannerController {

    @Autowired
    private BannerService bannerService;

    @ApiOperation(value = "轮播图列表",notes = "轮播图列表",httpMethod = "POST")
    @PostMapping("/list")
    public Result list(@RequestBody BannerDto bannerQueryDto){
        BannerVo bannerListVo = bannerService.findBannerAll(bannerQueryDto);
        return ResultUtils.buildSuccess(bannerListVo.getCount(),bannerListVo.getBannerList());
    }

    @ApiOperation(value = "添加轮播图",notes = "添加轮播图",httpMethod = "POST")
    @PostMapping("/add")
    public Result add(@RequestBody Banner banner){
        bannerService.insertBanner(banner);
        return ResultUtils.buildSuccess();
    }

    @ApiOperation(value = "修改轮播图",notes = "修改轮播图",httpMethod = "PUT")
    @PutMapping("/update")
    public Result update(@RequestBody Banner banner){
        bannerService.updateBanner(banner);
        return ResultUtils.buildSuccess();
    }


    @ApiOperation(value = "根据id删除轮播图",notes = "根据id删除轮播图",httpMethod = "DELETE")
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable("id") String id){
        bannerService.deleteBannerById(id);
        return ResultUtils.buildSuccess();
    }
}
